<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
    var src = 'http://localhost:8000/loading/resources/js-loaded.js?all-conn-types';
    var jsLoaded = false;
    var loadSuccess = false;
    var loadFailed = false;
    document.write('<scr' + 'ipt src="' + src + '?a" onload="loadSuccess=true" onError="loadFailed=true"></scr' + 'ipt>');
</script>

<script>
    test(function () {
        assert_true(jsLoaded);
        assert_true(loadSuccess);
        assert_false(loadFailed);
    }, "Document.written scripts are not blocked by default.");
</script>

<script>
    if (window.internals) {
        internals.settings.setDisallowFetchForDocWrittenScriptsInMainFrame(true);
        internals.setNetworkConnectionInfoOverride(true, 'wifi', '4g', 100, 2.0);
        internals.evictAllResources();

        window.addEventListener('beforeunload', function() {
            internals.clearNetworkConnectionInfoOverride();
            internals.settings.setDisallowFetchForDocWrittenScriptsInMainFrame(false);
        }, false);
    }
    jsLoaded = false;
    loadSuccess = false;
    loadFailed = false;
    // Append a distinct query string to the URL to avoid hitting the cache.
    // doc.written scripts are only blocked if they are not in cache.
    document.write('<scr' + 'ipt src="' + src + '?b" onload="loadSuccess=true" onError="loadFailed=true"></scr' + 'ipt>');
</script>
<script>
    test(function () {
        assert_false(jsLoaded);
        assert_false(loadSuccess);
        assert_true(loadFailed);
    }, "Document.written scripts are blocked on all connections when disallowFetchForDocWrittenScriptsInMainFrame is specified.");
</script>
